#include "PBDATA.H"

unsigned char dir = 0; // 默认向上

void DirKeyScan()
{
	unsigned char temp0 = 0, temp1 = 0, temp2 = 0;
	P1 = 0xFC;  // 1111 1100
	if(P1 != 0xFC) {
		delay(20);
		temp1 = P1;
		
		// 列
		P1 = 0xF3; // 1111 0011
		if(P1 != 0xF3) {
			temp2 = P1;
		}
	}
	
	temp0 = temp1 | temp2;
	if(temp0 == 0xFA) {  // 1111 1010 上
		dir = (dir == 2) ? dir : 0;
	} else if(temp0 == 0xF6) {  // 1111 0110 下
		dir = (dir == 0) ? dir : 2;
	} else if(temp0 == 0xF9) {  // 1111 1001 左
		dir = (dir == 1) ? dir : 3;
	} else if(temp0 == 0xF5) { // 1111 0101 右
		dir = (dir == 3) ? dir : 1;
	}
}